<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function getRandomColor(flag = true) { 
            if(flag){
                // 16进制颜色 #开头，0-9，a-f 任意6位组成
                let str = '#'
                // 把0-9，a-f 放到数组里边去，方便从数组随机取6位出来 
                let arr = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f']
                // 循环6次，用#拼接从数组里取出来的6个值
                for (let i = 0;i < 6; i++){
                    // 0-15的随机整数
                    let r =Math.floor(Math.random() * arr.length)
                    str = str + arr[r]
                }
                return str
            }else{
                //  输入rgb随机颜色 
                let a = Math.floor(Math.random() * 256)
                let b = Math.floor(Math.random() * 256)
                let c = Math.floor(Math.random() * 256)
            }
        }
       console.log(getRandomColor(true));
       console.log(getRandomColor());
       console.log(getRandomColor(false));
    </script>
</body>
</html>